package com.nl.lib_core.tool.coroutines.exception

import com.nl.lib_core.tool.coroutines.CoroutineExceptionListener
import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineExceptionHandler

/**
 * 作者: wangfei 创建时间: 2021/12/27 包名: com.nl.lib_core.tool.coroutines.exception 类名:
 * CaughtCoroutineExceptionHandler
 */
class CaughtCoroutineExceptionHandler(var listener: CoroutineExceptionListener?) :
    CoroutineExceptionHandler, AbstractCoroutineContextElement(CoroutineExceptionHandler.Key) {

  override fun handleException(context: CoroutineContext, exception: Throwable) {
    listener?.let { it(exception) }
  }
}
